# Utility class to evaluate a polynomial.
class PolyEvaluator():

  def __init__(self, weights):
    self.degree = len(weights) - 1
    self.weights = weights

  # Evaluate the polynomial.
  def evaluate(self, x):
    y = 0
    for i in range(0, self.degree + 1):
      y += self.weights[i] * (x**i)

    return y
  
  # Evaluate the polynomial and write the data for the range
  # 0, 0.01,..1.0
  def write_data(self, output_filepath):
    output_file = open(output_filepath, 'w')
    x = 0.0
    while x < 1.01:
      output_file.write('%f %f\n' % (x, self.evaluate(x))) 
      x += 0.01

    output_file.close()
